/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ControllerUI.java
 *
 * Created on Jan 19, 2012, 10:46:11 PM
 */
package sinchana.test;

/**
 *
 * @author Hiru
 */
public class ControllerUI extends javax.swing.JFrame {

	private TesterController testerController;

	/** Creates new form ControllerUI
	 * @param tc 
	 */
	public ControllerUI(TesterController tc) {
		this.testerController = tc;
		initComponents();
		setLocationRelativeTo(null);
		testerController.setSelection(TesterController.MESSAGE_TESTING);
		amountLabel.setText("Num of Msgs.");
		sendButton.setText("Send Msgs.");
		sendContinuousButton.setText("Send Continuously");
		storeButton.setEnabled(false);
		removeButton.setEnabled(false);
		sendButton.setEnabled(false);
		sendContinuousButton.setEnabled(false);
		printTableInfoButton.setEnabled(false);
		ringTestButton.setEnabled(false);
		printTableInfoId.setEditable(false);
		amountField.setEditable(false);
		amountLabel.setEnabled(false);
		messages.setSelected(true);
		messages.setEnabled(false);
		dataStore.setEnabled(false);
		services.setEnabled(false);
	}

	/**
	 * 
	 * @param status
	 */
	public void setStatus(String status) {
		this.statusField.setText(status);
	}

	public void setStat(String status) {
		this.statField.setText(status);
	}

	/** This method is called from within the constructor to
	 * initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is
	 * always regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        selectionGroup = new javax.swing.ButtonGroup();
        jPanel1 = new javax.swing.JPanel();
        startPanel = new javax.swing.JPanel();
        startNodeSetButton = new javax.swing.JButton();
        portRange = new javax.swing.JTextField();
        numOfTesters = new javax.swing.JTextField();
        testPanel = new javax.swing.JPanel();
        printTableInfoId = new javax.swing.JTextField();
        printTableInfoButton = new javax.swing.JButton();
        ringTestButton = new javax.swing.JButton();
        selectionPanel = new javax.swing.JPanel();
        messages = new javax.swing.JRadioButton();
        dataStore = new javax.swing.JRadioButton();
        services = new javax.swing.JRadioButton();
        messagePanel = new javax.swing.JPanel();
        amountLabel = new javax.swing.JLabel();
        amountField = new javax.swing.JTextField();
        sendButton = new javax.swing.JButton();
        sendContinuousButton = new javax.swing.JButton();
        servicePanel = new javax.swing.JPanel();
        storeButton = new javax.swing.JButton();
        removeButton = new javax.swing.JButton();
        statPanel = new javax.swing.JPanel();
        statField = new javax.swing.JLabel();
        statusField = new javax.swing.JLabel();
        loggerControlPanel = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        logNodeID = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        logType = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        logClass = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        logLocation = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        contatain = new javax.swing.JTextField();
        printLogButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Testing UI");
        getContentPane().setLayout(new java.awt.GridBagLayout());

        jPanel1.setLayout(new java.awt.GridLayout(6, 1, 0, 4));

        startPanel.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        startNodeSetButton.setText("Start Node Set");
        startNodeSetButton.setPreferredSize(new java.awt.Dimension(134, 24));
        startNodeSetButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                startNodeSetButtonActionPerformed(evt);
            }
        });
        startPanel.add(startNodeSetButton);

        portRange.setHorizontalAlignment(javax.swing.JTextField.TRAILING);
        portRange.setText("8000");
        portRange.setToolTipText("No of Testing Nodes");
        portRange.setPreferredSize(new java.awt.Dimension(96, 24));
        startPanel.add(portRange);

        numOfTesters.setHorizontalAlignment(javax.swing.JTextField.TRAILING);
        numOfTesters.setText("10");
        numOfTesters.setToolTipText("No of Testing Nodes");
        numOfTesters.setPreferredSize(new java.awt.Dimension(64, 24));
        startPanel.add(numOfTesters);

        jPanel1.add(startPanel);

        testPanel.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        printTableInfoId.setHorizontalAlignment(javax.swing.JTextField.TRAILING);
        printTableInfoId.setText("701EA28FCE4761E5C6866A4EB644661547A8D15C");
        printTableInfoId.setPreferredSize(new java.awt.Dimension(240, 24));
        testPanel.add(printTableInfoId);

        printTableInfoButton.setText("Print Table Info");
        printTableInfoButton.setPreferredSize(new java.awt.Dimension(134, 24));
        printTableInfoButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                printTableInfoButtonActionPerformed(evt);
            }
        });
        testPanel.add(printTableInfoButton);

        ringTestButton.setText("Test Ring");
        ringTestButton.setPreferredSize(new java.awt.Dimension(134, 24));
        ringTestButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ringTestButtonActionPerformed(evt);
            }
        });
        testPanel.add(ringTestButton);

        jPanel1.add(testPanel);

        selectionPanel.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        selectionGroup.add(messages);
        messages.setText("Messages");
        messages.setPreferredSize(new java.awt.Dimension(120, 24));
        messages.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                messagesActionPerformed(evt);
            }
        });
        selectionPanel.add(messages);

        selectionGroup.add(dataStore);
        dataStore.setText("Data Store");
        dataStore.setPreferredSize(new java.awt.Dimension(120, 24));
        dataStore.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                dataStoreActionPerformed(evt);
            }
        });
        selectionPanel.add(dataStore);

        selectionGroup.add(services);
        services.setText("Services");
        services.setPreferredSize(new java.awt.Dimension(120, 24));
        services.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                servicesActionPerformed(evt);
            }
        });
        selectionPanel.add(services);

        jPanel1.add(selectionPanel);

        messagePanel.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        amountLabel.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        amountLabel.setText("Amount");
        amountLabel.setPreferredSize(new java.awt.Dimension(96, 24));
        messagePanel.add(amountLabel);

        amountField.setHorizontalAlignment(javax.swing.JTextField.TRAILING);
        amountField.setText("1000");
        amountField.setToolTipText("No of Testing Nodes");
        amountField.setPreferredSize(new java.awt.Dimension(100, 24));
        messagePanel.add(amountField);

        sendButton.setText("Send Msg.");
        sendButton.setPreferredSize(new java.awt.Dimension(160, 24));
        sendButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sendButtonActionPerformed(evt);
            }
        });
        messagePanel.add(sendButton);

        sendContinuousButton.setText("Send Continuous");
        sendContinuousButton.setPreferredSize(new java.awt.Dimension(160, 24));
        sendContinuousButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sendContinuousButtonActionPerformed(evt);
            }
        });
        messagePanel.add(sendContinuousButton);

        jPanel1.add(messagePanel);

        servicePanel.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        storeButton.setText("Store");
        storeButton.setPreferredSize(new java.awt.Dimension(180, 24));
        storeButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                storeButtonActionPerformed(evt);
            }
        });
        servicePanel.add(storeButton);

        removeButton.setText("Remove");
        removeButton.setPreferredSize(new java.awt.Dimension(180, 24));
        removeButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                removeButtonActionPerformed(evt);
            }
        });
        servicePanel.add(removeButton);

        jPanel1.add(servicePanel);

        statPanel.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        statField.setText("Stat");
        statField.setPreferredSize(new java.awt.Dimension(520, 24));
        statPanel.add(statField);

        jPanel1.add(statPanel);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.insets = new java.awt.Insets(2, 0, 2, 0);
        getContentPane().add(jPanel1, gridBagConstraints);

        statusField.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        statusField.setText("Status...");
        statusField.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.insets = new java.awt.Insets(2, 0, 2, 0);
        getContentPane().add(statusField, gridBagConstraints);

        loggerControlPanel.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
        jLabel1.setText("Node ID");
        jLabel1.setPreferredSize(new java.awt.Dimension(48, 20));
        loggerControlPanel.add(jLabel1);

        logNodeID.setHorizontalAlignment(javax.swing.JTextField.TRAILING);
        logNodeID.setPreferredSize(new java.awt.Dimension(32, 20));
        loggerControlPanel.add(logNodeID);

        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
        jLabel2.setText("Type");
        jLabel2.setPreferredSize(new java.awt.Dimension(32, 20));
        loggerControlPanel.add(jLabel2);

        logType.setHorizontalAlignment(javax.swing.JTextField.TRAILING);
        logType.setPreferredSize(new java.awt.Dimension(32, 20));
        loggerControlPanel.add(logType);

        jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
        jLabel3.setText("Class");
        jLabel3.setPreferredSize(new java.awt.Dimension(36, 20));
        loggerControlPanel.add(jLabel3);

        logClass.setHorizontalAlignment(javax.swing.JTextField.TRAILING);
        logClass.setText("7");
        logClass.setPreferredSize(new java.awt.Dimension(32, 20));
        loggerControlPanel.add(logClass);

        jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
        jLabel4.setText("Location");
        jLabel4.setPreferredSize(new java.awt.Dimension(52, 20));
        loggerControlPanel.add(jLabel4);

        logLocation.setHorizontalAlignment(javax.swing.JTextField.TRAILING);
        logLocation.setText("0");
        logLocation.setPreferredSize(new java.awt.Dimension(32, 20));
        loggerControlPanel.add(logLocation);

        jLabel9.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
        jLabel9.setText("Contaions");
        jLabel9.setPreferredSize(new java.awt.Dimension(52, 20));
        loggerControlPanel.add(jLabel9);

        contatain.setHorizontalAlignment(javax.swing.JTextField.TRAILING);
        contatain.setPreferredSize(new java.awt.Dimension(64, 20));
        loggerControlPanel.add(contatain);

        printLogButton.setText("Print");
        printLogButton.setPreferredSize(new java.awt.Dimension(64, 24));
        printLogButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                printLogButtonActionPerformed(evt);
            }
        });
        loggerControlPanel.add(printLogButton);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridy = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        getContentPane().add(loggerControlPanel, gridBagConstraints);

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void printTableInfoButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_printTableInfoButtonActionPerformed
	testerController.printTableInfo(this.printTableInfoId.getText());
}//GEN-LAST:event_printTableInfoButtonActionPerformed

private void startNodeSetButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_startNodeSetButtonActionPerformed
	testerController.startNodeSet(Integer.parseInt(this.portRange.getText()),
			Integer.parseInt(this.numOfTesters.getText()));
	sendButton.setEnabled(true);
	sendContinuousButton.setEnabled(true);
	printTableInfoButton.setEnabled(true);
	ringTestButton.setEnabled(true);
	printTableInfoId.setEditable(true);
	amountField.setEditable(true);
	amountLabel.setEnabled(true);
	messages.setEnabled(true);
	dataStore.setEnabled(true);
	services.setEnabled(true);
}//GEN-LAST:event_startNodeSetButtonActionPerformed

private void ringTestButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ringTestButtonActionPerformed
	testerController.startRingTest();
}//GEN-LAST:event_ringTestButtonActionPerformed

private void printLogButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_printLogButtonActionPerformed
	testerController.printLogs(
			this.logNodeID.getText(),
			this.logType.getText(),
			this.logClass.getText(),
			this.logLocation.getText(),
			this.contatain.getText());
}//GEN-LAST:event_printLogButtonActionPerformed

private void storeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_storeButtonActionPerformed
	switch (testerController.testCaseSelection) {
		case TesterController.MESSAGE_TESTING:
			break;
		case TesterController.DATA_STORE_TESTING:
			testerController.storeData(Integer.parseInt(amountField.getText()));
			break;
		case TesterController.SERVICE_TESTING:
			testerController.publishService();
			break;
	}
}//GEN-LAST:event_storeButtonActionPerformed

private void removeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeButtonActionPerformed
	switch (testerController.testCaseSelection) {
		case TesterController.MESSAGE_TESTING:
			break;
		case TesterController.DATA_STORE_TESTING:
			testerController.removeData(Integer.parseInt(amountField.getText()));
			break;
		case TesterController.SERVICE_TESTING:
			testerController.removeService();
			break;
	}
}//GEN-LAST:event_removeButtonActionPerformed

private void sendButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sendButtonActionPerformed
	switch (testerController.testCaseSelection) {
		case TesterController.MESSAGE_TESTING:
			testerController.sendMsgs(Integer.parseInt(amountField.getText()));
			break;
		case TesterController.DATA_STORE_TESTING:
			testerController.retrieveData(Integer.parseInt(amountField.getText()));
			break;
		case TesterController.SERVICE_TESTING:
			testerController.invokeService(Integer.parseInt(amountField.getText()));
			break;
	}
}//GEN-LAST:event_sendButtonActionPerformed

private void sendContinuousButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sendContinuousButtonActionPerformed
	switch (testerController.testCaseSelection) {
		case TesterController.MESSAGE_TESTING:
			testerController.sendMsgsContinuously(Integer.parseInt(amountField.getText()));
			break;
		case TesterController.DATA_STORE_TESTING:
			testerController.retrieveDataContinuously(Integer.parseInt(amountField.getText()));
			break;
		case TesterController.SERVICE_TESTING:
			testerController.invokeServiceContinuously(Integer.parseInt(amountField.getText()));
			break;
	}
}//GEN-LAST:event_sendContinuousButtonActionPerformed

private void messagesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_messagesActionPerformed

	testerController.setSelection(TesterController.MESSAGE_TESTING);
	amountLabel.setText("Num of Msgs.");
	sendButton.setText("Send Msgs.");
	sendContinuousButton.setText("Send Continuously");
	storeButton.setEnabled(false);
	removeButton.setEnabled(false);
}//GEN-LAST:event_messagesActionPerformed

private void dataStoreActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_dataStoreActionPerformed

	testerController.setSelection(TesterController.DATA_STORE_TESTING);
	amountLabel.setText("Num of Data");
	sendButton.setText("Retrieve");
	sendContinuousButton.setText("Retrieve Continuously");
	storeButton.setText("Store Data");
	storeButton.setEnabled(true);
	removeButton.setText("Remove Data");
	removeButton.setEnabled(true);
}//GEN-LAST:event_dataStoreActionPerformed

private void servicesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_servicesActionPerformed

	testerController.setSelection(TesterController.SERVICE_TESTING);
	amountLabel.setText("Num of Invokes");
	sendButton.setText("Invoke Service");
	sendContinuousButton.setText("Invoke Continuously");
	storeButton.setText("Publish Service");
	storeButton.setEnabled(true);
	removeButton.setText("Remove Service");
	removeButton.setEnabled(true);
}//GEN-LAST:event_servicesActionPerformed
	/**
	 * @param args the command line arguments
	 */
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField amountField;
    private javax.swing.JLabel amountLabel;
    private javax.swing.JTextField contatain;
    private javax.swing.JRadioButton dataStore;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JTextField logClass;
    private javax.swing.JTextField logLocation;
    private javax.swing.JTextField logNodeID;
    private javax.swing.JTextField logType;
    private javax.swing.JPanel loggerControlPanel;
    private javax.swing.JPanel messagePanel;
    private javax.swing.JRadioButton messages;
    private javax.swing.JTextField numOfTesters;
    private javax.swing.JTextField portRange;
    private javax.swing.JButton printLogButton;
    private javax.swing.JButton printTableInfoButton;
    private javax.swing.JTextField printTableInfoId;
    private javax.swing.JButton removeButton;
    private javax.swing.JButton ringTestButton;
    private javax.swing.ButtonGroup selectionGroup;
    private javax.swing.JPanel selectionPanel;
    private javax.swing.JButton sendButton;
    private javax.swing.JButton sendContinuousButton;
    private javax.swing.JPanel servicePanel;
    private javax.swing.JRadioButton services;
    private javax.swing.JButton startNodeSetButton;
    private javax.swing.JPanel startPanel;
    private javax.swing.JLabel statField;
    private javax.swing.JPanel statPanel;
    private javax.swing.JLabel statusField;
    private javax.swing.JButton storeButton;
    private javax.swing.JPanel testPanel;
    // End of variables declaration//GEN-END:variables
}
